# -*- coding: utf-8 -*-
# @Author  : pony.guan
# @Time    : 2021/12/27 14:59
# Description: 子线程


import sys
import time
from threading import Thread
from PyQt5.QtWidgets import QApplication, QMainWindow

from untitled import Ui_MainWindow


class MyMainForm(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MyMainForm, self).__init__(parent)
        self.setupUi(self)

        # self.pushButton.clicked.connect(self.test)
        self.pushButton.clicked.connect(self.thread_test)

    def test(self):
        """
        @desc 显示效果是： 18秒后才显示所有的展示信息，不会有动态效果
        :return:
        """
        for i in range(6):
            self.textBrowser.append(f'执行时间: {i}')
            time.sleep(3)

    def thread_test(self):
        """
        @desc 动态显示输出，需要用子线程
        :return:
        """
        self.pushButton.setEnabled(False)  # 点击按钮后，立马禁用

        def func():
            for i in range(6):
                time.sleep(1)
                self.textBrowser.append(f'执行时间: {i}')

            self.pushButton.setEnabled(True)  # 任务执行完后，按钮解除禁用

        t = Thread(target=func)
        t.start()


if __name__ == "__main__":
    app = QApplication(sys.argv)

    myWin = MyMainForm()

    myWin.show()

    sys.exit(app.exec_())
